package gold.digger;

import java.util.*;

/**
 * Created by fanzhenyu02 on 2020/6/27.
 * common problem solver template.
 */
public class LC89 {
    public long startExecuteTime = System.currentTimeMillis();


    public List<Integer> grayCode(int n) {
        if (n <= 0) {
            return new ArrayList<>(Arrays.asList(0));
        }

        List<Integer> res = new ArrayList<>();
        List<Integer> subRes = grayCode(n - 1);
        res.addAll(subRes);
        for (int i = subRes.size() - 1; i >= 0; --i) {
            res.add(((int) Math.pow(2, n - 1)) + subRes.get(i));
        }

        return res;
    }

    public static void main(String[] args) throws Exception {
        LC89 an = new LC89();
        System.out.println(an.grayCode(2));

        System.out.println("\nanswer total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
